import 'package:flutter/material.dart';
import 'package:flutter_benchmarks/pages/render_images.dart';
import 'package:flutter_benchmarks/pages/render_texts.dart';
import 'package:flutter_benchmarks/pages/render_views.dart';

// 主界面展示列表，点击跳转对应的界面

class ScreenBean {
  String title;
  String desc;
  Widget screen;
  ScreenBean(this.title, this.desc, this.screen);
}

List<ScreenBean> pages = [
  ScreenBean("RenderViews", "性能测试Container场景 50", RenderViews(count: 50)),
  ScreenBean("RenderViews", "性能测试Container场景 200", RenderViews(count: 200)),
  ScreenBean("RenderViews", "性能测试Container场景 1500", RenderViews(count: 1500)),
  ScreenBean("RenderTexts", "性能测试Text场景 50", RenderTexts(count: 50)),
  ScreenBean("RenderTexts", "性能测试Text场景 200", RenderTexts(count: 200)),
  ScreenBean("RenderTexts", "性能测试Text场景 1500", RenderTexts(count: 1500)),
  ScreenBean("RenderImages", "性能测试Image场景 50", RenderImages(count: 50)),
  ScreenBean("RenderImages", "性能测试Image场景 200", RenderImages(count: 200)),
  ScreenBean("RenderImages", "性能测试Image场景 1500", RenderImages(count: 1500)),
];

class MyHomePage extends StatelessWidget {
  String title;

  MyHomePage({super.key, required this.title});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(title)),
      body: ListView.builder(
        itemCount: pages.length,
        itemBuilder: (context, index) {
          ScreenBean pageItem = pages[index];
          return ListTile(
            title: Text(pageItem.title),
            subtitle: Text(pageItem.desc),
            onTap: () => _goToPage(context, pageItem),
          );
        },
      ),
    );
  }

  _goToPage(BuildContext context, ScreenBean pageItem) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => pageItem.screen,
      ),
    );
  }
}
